<?php if (!defined("_ECRIRE_INC_VERSION")) return;
/**
 *  RadioDJ
 *
 * @author     Aleksey Yaroshchuk (aleksey.yaroshchuk@gmail.com)
 * @license    GNU/GPL
 * @package    plugins
 * @subpackage radiodj
 * @copyright  (c) Aleksey Yaroshchuk 2011-2012
 * @link       http://www.spip-contrib.net/RadioDJ
 */
 
    function radiodj_insert_head($flux){        
        $flux .= '<link rel="stylesheet" type="text/css" href="'.find_in_path('radiodj.css').'" media="all" />';
        
        $script = recuperer_fond('js/radiodj_config');
        $flux .= $script;
        $flux .= "<script language='JavaScript' type='text/javascript' src='".find_in_path('js/cookies.js')."'></script>\n";
        $flux .= "<script language='JavaScript' type='text/javascript' src='".find_in_path('js/radiodj_city.js')."'></script>\n";
        //$script = recuperer_fond('js/radiodj', array(), array('trim'=>false));
        //$flux .= "<script language='JavaScript' type='text/javascript' src='".find_in_path('js/radiodj.js')."'></script>\n";
		$flux .= "<script language='JavaScript' type='text/javascript' src='".find_in_path('js/radiodj.php')."'></script>\n";
              
        /*$flux .= '<?php var_dump("!!!"); ?>';*/ // Такая штука катит
        return $flux;
    }
    
    function radiodj_formulaire_traiter($flux){        
        // Если сохраняем конфигурацию, необходимо поменять плейлист для плеера
        $player_titre = lire_config('radiodj/PlayerTitle');
        $player_titre = $player_titre ? $player_titre : $GLOBALS['meta']['nom_site'];
        if ($flux['args']['form'] == 'configurer_radiodj') {
            file_put_contents(_DIR_PLUGIN_RADIODJ.'mju/playlist.mpl', 
            '<stream artist="'.$player_titre.'" title="Listen online" url="'.lire_config('radiodj/AudioLink').'" />');
            
            $file_text = file_get_contents(_DIR_PLUGIN_RADIODJ.'update_songs_cron.php');
            $pattern = '/\$filename = \'\.\.\/\.\.\/\'\.\'.*\'; \/\/ Do not change this string!/';
            $replacement = '$filename = \'../../\'.\''.lire_config('radiodj/XMLfile').'\'; // Do not change this string!';
            $file_text = preg_replace($pattern, $replacement, $file_text);                        
            file_put_contents(_DIR_PLUGIN_RADIODJ.'update_songs_cron.php', $file_text);
            
            
        }
        return $flux;
    }

?>